# -*- coding: UTF-8 -*-
import scrapy
import messAround.util.help as util


# steam 硬件统计
# https://store.steampowered.com/hwsurvey
class SteamHardwareSpider(scrapy.Spider):
    name = 'steam_hardware'
    allowed_domains = ['store.steampowered.com']
    start_urls = ['http://store.steampowered.com/']

    def start_requests(self):
        urls = [
            'https://store.steampowered.com/hwsurvey'
        ]
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse, headers=util.default_headers)

    def parse(self, response):

        yield util.make_data({
            'source': 1,
            'os_version_name': response.xpath('//*[@id="osversion_val_1_on"]/text()').get(),
            'os_version_percent': response.xpath('//*[@id="osversion_val_2_on"]/text()').get(),
            'os_version_trend': response.xpath('//*[@id="osversion_val_3_on"]/text()').get(),

            'sys_ram_name': response.xpath('//*[@id="cat0_val_1_on"]/text()').get(),
            'sys_ram_percent': response.xpath('//*[@id="cat0_val_2_on"]/text()').get(),
            'sys_ram_trend': response.xpath('//*[@id="cat0_val_3_on"]/text()').get(),

            'cpu_speed_name': response.xpath('//*[@id="cat1_val_1_on"]/text()').get(),
            'cpu_speed_percent': response.xpath('//*[@id="cat1_val_2_on"]/text()').get(),
            'cpu_speed_trend': response.xpath('//*[@id="cat1_val_3_on"]/text()').get(),

            'cpus_name': response.xpath('//*[@id="cat2_val_1_on"]/text()').get(),
            'cpus_percent': response.xpath('//*[@id="cat2_val_2_on"]/text()').get(),
            'cpus_trend': response.xpath('//*[@id="cat2_val_3_on"]/text()').get(),

            'language_name': response.xpath('//*[@id="cat10_val_1_on"]/text()').get(),
            'language_percent': response.xpath('//*[@id="cat10_val_2_on"]/text()').get(),
            'language_trend': response.xpath('//*[@id="cat10_val_3_on"]/text()').get(),

            'hard_name': response.xpath('//*[@id="cat10_val_1_on"]/text()').get(),
            'hard_percent': response.xpath('//*[@id="cat10_val_2_on"]/text()').get(),
            'hard_trend': response.xpath('//*[@id="cat10_val_3_on"]/text()').get(),
        })

